home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS05.ADF / IFF / spec8bsv < prev    next >
Text File  |  1986-04-20  |  28KB  |  643 lines

  1.  
  2. "8SVX" IFF 8-Bit Sampled Voice
  3.  
  4. Date:     February 7, 1985
  5. From:     Steve Hayes and Jerry Morrison, Electronic Arts
  6. Status:   Adopted
  7.  
  8. 1. Introduction
  9.  
  10. This memo is the IFF supplement for FORM "8SVX". An 8SVX is an IFF 
  11. "data section" or "FORM" (which can be an IFF file or a part of one) 
  12. containing a digitally sampled audio voice consisting of 8-bit samples. 
  13. A voice can be a one-shot sound orQwith repetition and pitch scalingQa 
  14. musical instrument. "EA IFF 85" is Electronic Arts' standard interchange 
  15. file format. [See "EA IFF 85" Standard for Interchange Format Files.]
  16.  
  17. The 8SVX format is designed for playback hardware that uses 8-bit 
  18. samples attenuated by a volume control for good overall signal-to-noise 
  19. ratio. So a FORM 8SVX stores 8-bit samples and a volume level.
  20.  
  21. A similar data format (or two) will be needed for higher resolution 
  22. samples (typically 12 or 16 bits). Properly converting a high resolution 
  23. sample down to 8 bits requires one pass over the data to find the 
  24. minimum and maximum values and a second pass to scale each sample 
  25. into the range -128 through 127. So it's reasonable to store higher 
  26. resolution data in a different FORM type and convert between them.
  27.  
  28. For instruments, FORM 8SVX can record a repeating waveform optionally 
  29. preceded by a startup transient waveform. These two recorded signals 
  30. can be pre-synthesized or sampled from an acoustic instrument. For 
  31. many instruments, this representation is compact. FORM 8SVX is less 
  32. practical for an instrument whose waveform changes from cycle to cycle 
  33. like a plucked string, where a long sample is needed for accurate 
  34. results.
  35.  
  36. FORM 8SVX can store an "envelope" or "amplitude contour" to enrichen 
  37. musical notes. A future voice FORM could also store amplitude, frequency, 
  38. and filter modulations.
  39.  
  40. FORM 8SVX is geared for relatively simple musical voices, where one 
  41. waveform per octave is sufficient, where the waveforms for the different 
  42. octaves follows a factor-of-two size rule, and where one envelope 
  43. is adequate for all octaves. You could store a more general voice 
  44. as a LIST containing one or more FORMs 8SVX per octave. A future voice 
  45. FORM could go beyond one "one-shot" waveform and one "repeat" waveform 
  46. per octave.
  47.  
  48. Section 2 defines the required property sound header "VHDR", optional 
  49. properties name "NAME", copyright "(c)J", and author "AUTH", the optional 
  50. annotation data chunk "ANNO", the required data chunk "BODY", and 
  51. optional envelope chunks "ATAK" and "RLSE". These are the "standard" 
  52. chunks. Specialized chunks for private or future needs can be added 
  53. later, e.g. to hold a frequency contour or Fourier series coefficients. 
  54. The 8SVX syntax is summarized in Appendix A as a regular expression 
  55. and in Appendix B as an example box diagram. Appendix C explains the 
  56. optional Fibonacci-delta compression algorithm.
  57.  
  58. Caution: The VHDR structure Voice8Header changed since draft proposal 
  59. #4! The new structure is incompatible with the draft version.
  60.  
  61. Reference:
  62.  
  63. "EA IFF 85" Standard for Interchange Format Files describes the underlying 
  64. conventions for all IFF files.
  65.  
  66. Amiga[tm] is a trademark of Commodore-Amiga, Inc.
  67.  
  68. Electronic Arts[tm] is a trademark of Electronic Arts.
  69.  
  70. MacWrite[tm] is a trademark of Apple Computer, Inc.
  71.  
  72. 2. Standard Data and Property Chunks
  73.  
  74. FORM 8SVX stores all the waveform data in one body chunk "BODY". It 
  75. stores playback parameters in the required header chunk "VHDR". "VHDR" 
  76. and any optional property chunks "NAME", "(c)J", and "AUTH" must all 
  77. appear before the BODY chunk. Any of these properties may be shared 
  78. over a LIST of FORMs 8SVX by putting them in a PROP 8SVX. [See "EA 
  79. IFF 85" Standard for Interchange Format Files.]
  80.  
  81. Background
  82.  
  83. There are two ways to use FORM 8SVX: as a one-shot sampled sound or 
  84. as a sampled musical instrument that plays "notes". Storing both kinds 
  85. of sounds in the same kind of FORM makes it easy to play a one-shot 
  86. sound as a (staccato) instrument or an instrument as a (one-note) 
  87. sound.
  88.  
  89. A one-shot sound is a series of audio data samples with a nominal 
  90. playback rate and amplitude. The recipient program can optionally 
  91. adjust or modulate the amplitude and playback data rate.
  92.  
  93. For musical instruments, the idea is to store a sampled (or pre-synthesized) 
  94. waveform that will be parameterized by pitch, duration, and amplitude 
  95. to play each "note". The creator of the FORM 8SVX can supply a waveform 
  96. per octave over a range of octaves for this purpose. The intent is 
  97. to perform a pitch by selecting the closest octave's waveform and 
  98. scaling the playback data rate. An optional "one-shot" waveform supplies 
  99. an arbitrary startup transient, then a "repeat" waveform is iterated 
  100. as long as necessary to sustain the note.
  101.  
  102. A FORM 8SVX can also store an envelope to modulate the waveform. Envelopes 
  103. are mostly useful for variable-duration notes but could be used for 
  104. one-shot sounds, too.
  105.  
  106. The FORM 8SVX standard has some restrictions. For example, each octave 
  107. of data must be twice as long as the next higher octave. Most sound 
  108. driver software and hardware imposes additional restrictions. E.g. 
  109. the Amiga sound hardware requires an even number of samples in each 
  110. one-shot and repeat waveform.
  111.  
  112. Required Property VHDR
  113.  
  114. The required property "VHDR" holds a Voice8Header structure as defined 
  115. in these C declarations and following documentation. This structure 
  116. holds the playback parameters for the sampled waveforms in the BODY 
  117. chunk. (See "Data Chunk BODY", below, for the storage layout of these 
  118. waveforms.)
  119.  
  120. #define ID_8SVX MakeID('8', 'S', 'V', 'X')
  121. #define ID_VHDR MakeID('V', 'H', 'D', 'R')
  122.  
  123. typedef LONG Fixed; 
  124.      /* A fixed-point value, 16 bits to the left of the point and 16 
  125.       * to the right. A Fixed is a number of 216ths, i.e. 65536ths.   */
  126.  
  127. #define Unity 0x10000L   /* Unity = Fixed 1.0 = maximum volume   */
  128.  
  129. /* sCompression: Choice of compression algorithm applied to the samples. */ 
  130.  
  131. #define sCmpNone       0 /* not compressed   */
  132. #define sCmpFibDelta   1 /* Fibonacci-delta encoding (Appendix C)  */ 
  133.  
  134. /* Can be more kinds in the future.     */
  135.  
  136. typedef struct {
  137.      ULONG oneShotHiSamples,  /* # samples in the high octave 1-shot part */
  138.         repeatHiSamples, /* # samples in the high octave repeat part */
  139.         samplesPerHiCycle;    /* # samples/cycle in high octave, else 0   */
  140.      UWORD samplesPerSec;     /* data sampling rate    */
  141.      UBYTE ctOctave,          /* # octaves of waveforms     */
  142.           sCompression;       /* data compression technique used */
  143.      Fixed volume;       /* playback volume from 0 to Unity (full 
  144.                      * volume). Map this value into the output 
  145.                      * hardware's dynamic range.  */
  146.      } Voice8Header;
  147.  
  148. [Implementation details. Fields are filed in the order shown. The 
  149. UBYTE fields are byte-packed (2 per 16-bit word). MakeID is a C macro 
  150. defined in the main IFF document and in the source file IFF.h.]
  151.  
  152. A FORM 8SVX holds waveform data for one or more octaves, each containing 
  153. a one-shot part and a repeat part. The fields oneShotHiSamples and 
  154. repeatHiSamples tell the number of audio samples in the two parts 
  155. of the highest frequency octave. Each successive (lower frequency) 
  156. octave contains twice as many data samples in both its one-shot and 
  157. repeat parts. One of these two parts can be empty across all octaves.
  158.  
  159. Note: Most audio output hardware and software has limitations. The 
  160. Amiga computer's sound hardware requires that all one-shot and repeat 
  161. parts have even numbers of samples. Amiga sound driver software would 
  162. have to adjust an odd-sized waveform, ignore an odd-sized lowest octave, 
  163. or ignore odd FORMs 8SVX altogether. Some other output devices require 
  164. all sample sizes to be powers of two.
  165.  
  166. The field samplesPerHiCycle tells the number of samples/cycle in the 
  167. highest frequency octave of data, or else 0 for "unknown". Each successive 
  168. (lower frequency) octave contains twice as many samples/cycle. The 
  169. samplesPerHiCycle value is needed to compute the data rate for a desired 
  170. playback pitch.
  171.  
  172. Actually, samplesPerHiCycle is an average number of samples/cycle. 
  173. If the one-shot part contains pitch bends, store the samples/cycle 
  174. of the repeat part in samplesPerHiCycle. The division repeatHiSamples/samplesPe
  175. rHiCycle should yield an integer number of cycles. (When the repeat 
  176. waveform is repeated, a partial cycle would come out as a higher-frequency 
  177. cycle with a "click".)
  178.  
  179. More limitations: Some Amiga music drivers require samplesPerHiCycle 
  180. to be a power of two in order to play the FORM 8SVX as a musical instrument 
  181. in tune. They may even assume samplesPerHiCycle is a particular power 
  182. of two without checking. (If samplesPerHiCycle is different by a factor 
  183. of two, the instrument will just be played an octave too low or high.)
  184.  
  185. The field samplesPerSec gives the sound sampling rate. A program may 
  186. adjust this to achieve frequency shifts or vary it dynamically to 
  187. achieve pitch bends and vibrato. A program that plays a FORM 8SVX 
  188. as a musical instrument would ignore samplesPerSec and select a playback 
  189. rate for each musical pitch.
  190.  
  191. The field ctOctave tells how many octaves of data are stored in the 
  192. BODY chunk. See "Data Chunk BODY", below, for the layout of the octaves.
  193.  
  194. The field sCompression indicates the compression scheme, if any, that 
  195. was applied to the entire set of data samples stored in the BODY chunk. 
  196. This field should contain one of the values defined above. Of course, 
  197. the matching decompression algorithm must be applied to the BODY data 
  198. before the sound can be played. (The Fibonacci-delta encoding scheme 
  199. sCmpFibDelta is described in Appendix C.) Note that the whole series 
  200. of data samples is compressed as a unit.
  201.  
  202. The field volume gives an overall playback volume for the waveforms 
  203. (all octaves). It lets the 8-bit data samples use the full range -128 
  204. through 127 for good signal-to-noise ratio and be attenuated on playback 
  205. to the desired level. The playback program should multiply this value 
  206. by a "volume control" and perhaps by a playback envelope (see ATAK 
  207. and RLSE, below).
  208.  
  209. Recording a one-shot sound. To store a one-shot sound in a FORM 8SVX, 
  210. set oneShotHiSamples = number of samples, repeatHiSamples = 0 , 
  211. samplesPerHiCycle = 0, samplesPerSec = sampling rate, and ctOctave = 1. 
  212. Scale the signal amplitude to the full sampling range -128 through 127. Set 
  213. volume so the sound will playback at the desired volume level. If 
  214. you set the samplesPerHiCycle field properly, the data can also be 
  215. used as a musical instrument.
  216.  
  217. Experiment with data compression. If the decompressed signal sounds 
  218. ok, store the compressed data in the BODY chunk and set sCompression 
  219. to the compression code number.
  220.  
  221. Recording a musical instrument. To store a musical instrument in a 
  222. FORM 8SVX, first record or synthesize as many octaves of data as you 
  223. want to make available for playback. Set ctOctaves to the count of 
  224. octaves. From the recorded data, excerpt an integral number of steady 
  225. state cycles for the repeat part and set repeatHiSamples and samplesPerHiCycle. 
  226. Either excerpt a startup transient waveform and set oneShotHiSamples, 
  227. or else set oneShotHiSamples to 0. Remember, the one-shot and repeat 
  228. parts of each octave must be twice as long as those of the next higher 
  229. octave. Scale the signal amplitude to the full sampling range and 
  230. set volume to adjust the instrument playback volume. If you set the 
  231. samplesPerSec field properly, the data can also be used as a one-shot 
  232. sound.
  233.  
  234. A distortion-introducing compressor like sCmpFibDelta is not recommended 
  235. for musical instruments, but you might try it anway.
  236.  
  237. Typically, creators of FORM 8SVX record an acoustic instrument at 
  238. just one frequency. Decimate (down- sample with filtering) to compute 
  239. higher octaves. Interpolate to compute lower octaves.
  240.  
  241. If you sample an acoustic instrument at different octaves, you may 
  242. find it hard to make the one-shot and repeat waveforms follow the 
  243. factor-of-two rule for octaves. To compensate, lengthen an octave's 
  244. one-shot part by appending replications of the repeating cycle or 
  245. prepending zeros. (This will have minimal impact on the sound's start 
  246. time.) You may be able to equalize the ratio one-shot-samples : repeat-samples 
  247. across all octaves.
  248.  
  249. Note that a "one-shot sound" may be played as a "musical instrument" 
  250. and vice versa. However, an instrument player depends on samplesPerHiCycle, 
  251. and a one-shot player depends on samplesPerSec.
  252.  
  253. Playing a one-shot sound. To play any FORM 8SVX data as a one-shot 
  254. sound, first select an octave if ctOctave > 1. (The lowest-frequency 
  255. octave has the greatest resolution.) Play the one-shot samples then 
  256. the repeat samples, scaled by volume, at a data rate of samplesPerSec. 
  257. Of course, you may adjust the playback rate and volume. You can play 
  258. out an envelope, too. (See ATAK and RLSE, below.)
  259.  
  260. Playing a musical note. To play a musical note using any FORM 8SVX, 
  261. first select the nearest octave of data from those available. Play 
  262. the one-shot waveform then cycle on the repeat waveform as long as 
  263. needed to sustain the note. Scale the signal by volume, perhaps also 
  264. by an envelope, and by a desired note volume. Select a playback data 
  265. rate s samples/second to achieve the desired frequency (in Hz):
  266. frequency = sJ/JsamplesPerHiCycle
  267. for the highest frequency octave.
  268.  
  269. The idea is to select an octave and one of 12 sampling rates (assuming 
  270. a 12-tone scale). If the FORM 8SVX doesn't have the right octave, 
  271. you can decimate or interpolate from the available data.
  272.  
  273. When it comes to musical instruments, FORM 8SVX is geared for a simple 
  274. sound driver. Such a driver uses a single table of 12 data rates to 
  275. reach all notes in all octaves. That's why 8SVX requires each octave 
  276. of data to have twice as many samples as the next higher octave. If 
  277. you restrict samplesPerHiCycle to a power of two, you can use a predetermined 
  278. table of data rates.
  279.  
  280. Optional Text Chunks NAME, (c), AUTH, ANNO
  281.  
  282. Several text chunks may be included in a FORM 8SVX to keep ancillary 
  283. information.
  284.  
  285. The optional property "NAME" names the voice, for instance "tubular 
  286. bells".
  287.  
  288. The optional property "(c)J" holds a copyright notice for the voice. 
  289. The chunk ID "(c)J" serves as the copyright characters ")J". E.g. 
  290. a "(c)J" chunk containing "1986 Electronic Arts" means ") 1986 Electronic 
  291. Arts".
  292.  
  293. The optional property "AUTH" holds the name of the instrument's "author" 
  294. or "creator".
  295.  
  296. The chunk types "NAME", "(c) ", and "AUTH" are property chunks. Putting 
  297. more than one NAME (or other) property in a FORM is redundant. Just 
  298. the last NAME counts. A property should be shorter than 256 characters. 
  299. Properties can appear in a PROP 8SVX to share them over a LIST of 
  300. FORMs 8SVX.
  301.  
  302. The optional data chunk "ANNO" holds any text annotations typed in 
  303. by the author.
  304.  
  305. An ANNO chunk is not a property chunk, so you can put more than one 
  306. in a FORM 8SVX. You can make ANNO chunks any length up to 231 - 1 
  307. characters, but 32767 is a practical limit. Since they're not properties, 
  308. ANNO chunks don't belong in a PROP 8SVX. That means they can't be 
  309. shared over a LIST of FORMs 8SVX.
  310.  
  311. Syntactically, each of these chunks contains an array of 8-bit ASCII 
  312. characters in the range " " (SP, hex 20) through "~" (tilde, hex 7F), 
  313. just like a standard "TEXT" chunk. [See "Strings, String Chunks, and 
  314. String Properties" in "EA IFF 85" Electronic Arts Interchange File 
  315. Format.] The chunk's ckSize field holds the count of characters.
  316.  
  317. #define ID_NAME MakeID('N', 'A', 'M', 'E')
  318. /* NAME chunk contains a CHAR[], the voice's name.     */
  319.  
  320. #define ID_Copyright MakeID('(', 'c', ')', ' ')
  321. /* "(c) " chunk contains a CHAR[], the FORM's copyright notice.  */
  322.  
  323. #define ID_AUTH MakeID('A', 'U', 'T', 'H')
  324. /* AUTH chunk contains a CHAR[], the author's name.    */
  325.  
  326. #define ID_ANNO MakeID('A', 'N', 'N', 'O')
  327. /* ANNO chunk contains a CHAR[], author's text annotations. */
  328.  
  329. Remember to store a 0 pad byte after any odd-length chunk.
  330.  
  331. Optional Data Chunks ATAK and RLSE
  332.  
  333. The optional data chunks ATAK and RLSE together give a piecewise-linear 
  334. "envelope" or "amplitude contour". This contour may be used to modulate 
  335. the sound during playback. It's especially useful for playing musical 
  336. notes of variable durations. Playback programs may ignore the supplied 
  337. envelope or substitute another.
  338.  
  339. #define ID_ATAK MakeID('A', 'T', 'A', 'K')
  340. #define ID_RLSE MakeID('R', 'L', 'S', 'E')
  341.  
  342. typedef struct {
  343.      UWORD duration;     /* segment duration in milliseconds, > 0     */
  344.      Fixed dest;    /* destination volume factor  */
  345.      } EGPoint;
  346.  
  347. /* ATAK and RLSE chunks contain an EGPoint[], piecewise-linear envelope.*/ 
  348. /* The envelope defines a function of time returning Fixed values. It's
  349.  * used to scale the nominal volume specified in the Voice8Header. */
  350.  
  351. To explain the meaning of the ATAK and RLSE chunks, we'll overview 
  352. the envelope generation algorithm. Start at 0 volume, step through 
  353. the ATAK contour, then hold at the sustain level (the last ATAK EGPoint's 
  354. dest), and then step through the RLSE contour. Begin the release at 
  355. the desired note stop time minus the total duration of the release 
  356. contour (the sum of the RLSE EGPoints' durations). The attack contour 
  357. should be cut short if the note is shorter than the release contour.
  358.  
  359. The envelope is a piecewise-linear function. The envelope generator 
  360. interpolates between the EGPoints.
  361.  
  362. Remember to multiply the envelope function by the nominal voice header 
  363. volume and by any desired note volume.
  364.  
  365. Figure 1 shows an example envelope. The attack period is described 
  366. by 4 EGPoints in an ATAK chunk. The release period is described by 
  367. 4 EGPoints in a RLSE chunk. The sustain period in the middle just 
  368. holds the final ATAK level until it's time for the release.
  369.  
  370. `0C
  371.  
  372.                Figure 1. Amplitude contour.
  373.  
  374. Note: The number of EGPoints in an ATAK or RLSE chunk is its ckSize 
  375. / sizeof(EGPoint). In RAM, the playback program may terminate the 
  376. array with a 0 duration EGPoint.
  377.  
  378. Issue: Synthesizers also provide frequency contour (pitch bend), filtering 
  379. contour (wah-wah), amplitude oscillation (tremolo), frequency oscillation 
  380. (vibrato), and filtering oscillation (leslie). In the future, we may 
  381. define optional chunks to encode these modulations. The contours can 
  382. be encoded in linear segments. The oscillations can be stored as segments 
  383. with rate and depth parameters.
  384.  
  385. Data Chunk BODY
  386.  
  387. The BODY chunk contains the audio data samples.
  388.  
  389. #define ID_BODY MakeID('B', 'O', 'D', 'Y')
  390.  
  391. typedef character BYTE;  /* 8 bit signed number, -128 through 127.    */
  392.  
  393. /* BODY chunk contains a BYTE[], array of audio data samples.    */
  394.  
  395. The BODY contains data samples grouped by octave. Within each octave 
  396. are one-shot and repeat portions. Figure 2 depicts this arrangement 
  397. of samples for an 8SVX where oneShotHiSamples = 24, repeatHiSamples 
  398. = 16, samplesPerHiCycle = 8, and ctOctave = 3. The major divisions 
  399. are octaves, the intermediate divisions separate the one-shot and 
  400. repeat portions, and the minor divisions are cycles.
  401.  
  402. `0C
  403.  
  404.                Figure 2. BODY subdivisions.
  405.  
  406. In general, the BODY has ctOctave octaves of data. The highest frequency 
  407. octave comes first, comprising the fewest samples: oneShotHiSamples 
  408. + repeatHiSamples. Each successive octave contains twice as many samples 
  409. as the next higher octave but the same number of cycles. The lowest 
  410. frequency octave comes last with the most samples: 2ctOctave-1 * (oneShotHiSamp
  411. les + repeatHiSamples).
  412.  
  413. The number of samples in the BODY chunk is
  414.  
  415.   0          (ctOctave-1) 
  416. (2  + ... + 2            * (oneShotHiSamples + repeatHiSamples)
  417.  
  418. Figure 3, below, looks closer at an example waveform within one octave 
  419. of a different BODY chunk. In this example, oneShotHiSamples / samplesPerHiCycl
  420. e = 2 cycles and repeatHiSamples / samplesPerHiCycle = 1 cycle.
  421.  
  422. `0C
  423.  
  424.                Figure 3. Example waveform.
  425.  
  426. To avoid playback "clicks", the one-shot part should begin with a 
  427. small sample value, and the one-shot part should flow smoothly into 
  428. the repeat part, and the end of the repeat part should flow smoothly 
  429. into the beginning of the repeat part.
  430.  
  431. If the VHDR field sCompression - sCmpNone, the BODY chunk is just 
  432. an array of data bytes to feed through the specified decompresser 
  433. function. All this stuff about sample sizes, octaves, and repeat parts 
  434. applies to the decompressed data.
  435.  
  436. Be sure to follow an odd-length BODY chunk with a 0 pad byte.
  437.  
  438. Other Chunks
  439.  
  440. Issue: In the future, we may define an optional chunk containing Fourier 
  441. series coefficients for a repeating waveform. An editor for this kind 
  442. of synthesized voice could modify the coefficients and regenerate 
  443. the waveform.
  444.  
  445. `0C
  446. Appendix A. Quick Reference
  447.  
  448. Type Definitions
  449.  
  450. #define ID_8SVX MakeID('8', 'S', 'V', 'X')
  451. #define ID_VHDR MakeID('V', 'H', 'D', 'R')
  452.  
  453. typedef LONG Fixed; /* A fixed-point value, 16 bits to the left 
  454.                 * of the point and 16 to the right. A Fixed 
  455.                 * is a number of 216ths, i.e. 65536ths. */
  456.  
  457. #define Unity 0x10000L   /* Unity = Fixed 1.0 = maximum volume   */
  458.  
  459. /* sCompression: Choice of compression algorithm applied to the samples    */ 
  460.  
  461. #define sCmpNone       0 /* not compressed   */
  462. #define sCmpFibDelta   1 /* Fibonacci-delta encoding (Appendix C) */
  463.      /* Can be more kinds in the future.     */
  464.  
  465. typedef struct {
  466.      ULONG oneShotHiSamples,  /* # samples in the high octave 1-shot part */
  467.         repeatHiSamples, /* # samples in the high octave repeat part */
  468.         samplesPerHiCycle;    /* # samples/cycle in high octave, else 0   */
  469.      UWORD samplesPerSec;     /* data sampling rate    */
  470.      UBYTE ctOctave,          /* # octaves of waveforms     */ 
  471.      sCompression;       /* data compression technique used */
  472.      Fixed volume;       /* playback volume from 0 to Unity (full
  473.                      * volume). Map this value into the output
  474.                      * hardware's dynamic range.  */
  475.      } Voice8Header;
  476.  
  477. #define ID_NAME MakeID('N', 'A', 'M', 'E')
  478. /* NAME chunk contains a CHAR[], the voice's name.     */
  479.  
  480. #define ID_Copyright MakeID('(', 'c', ')', ' ')
  481. /* "(c) " chunk contains a CHAR[], the FORM's copyright notice.  */
  482.  
  483. #define ID_AUTH MakeID('A', 'U', 'T', 'H')
  484. /* AUTH chunk contains a CHAR[], the author's name.    */
  485.  
  486. #define ID_ANNO MakeID('A', 'N', 'N', 'O')
  487. /* ANNO chunk contains a CHAR[], author's text annotations. */
  488.  
  489. #define ID_ATAK MakeID('A', 'T', 'A', 'K')
  490. #define ID_RLSE MakeID('R', 'L', 'S', 'E')
  491.  
  492. typedef struct {
  493.      UWORD duration;     /* segment duration in milliseconds, > 0     */
  494.      Fixed dest;    /* destination volume factor  */
  495.      } EGPoint;
  496.  
  497. /* ATAK and RLSE chunks contain an EGPoint[], piecewise-linear envelope. */
  498. /* The envelope defines a function of time returning Fixed values. It's
  499.  * used to scale the nominal volume specified in the Voice8Header.  */
  500.  
  501. #define ID_BODY MakeID('B', 'O', 'D', 'Y')
  502.  
  503. typedef character BYTE;  /* 8 bit signed number, -128 through 127.    */
  504.  
  505. /* BODY chunk contains a BYTE[], array of audio data samples.    */
  506.  
  507. 8SVX Regular Expression
  508.  
  509. Here's a regular expression summary of the FORM 8SVX syntax. This 
  510. could be an IFF file or part of one.
  511.  
  512. 8SVX ::= "FORM" #{  "8SVX" VHDR [NAME] [Copyright] [AUTH] ANNO*
  513.           [ATAK] [RLSE] BODY }
  514.  
  515. VHDR ::= "VHDR" #{ Voice8Header    }
  516. NAME ::= "NAME" #{ CHAR* } [0]
  517. Copyright ::= "(c) " #{ CHAR* } [0]
  518. AUTH ::= "AUTH" #{ CHAR* } [0]
  519. ANNO ::= "ANNO" #{ CHAR* } [0]
  520.  
  521. ATAK ::= "ATAK" #{ EGPoint*   }
  522. RLSE ::= "RLSE" #{ EGPoint*   }
  523. BODY ::= "FORM" #{ BYTE* } [0]
  524.  
  525. The token "#" represents a ckSize LONG count of the following {braced} 
  526. data bytes. E.g. a VHDR's "#" should equal sizeof(Voice8Header). Literal 
  527. items are shown in "quotes", [square bracket items] are optional, 
  528. and "*" means 0 or more replications. A sometimes-needed pad byte 
  529. is shown as "[0]".
  530.  
  531. Actually, the order of chunks in a FORM 8SVX is not as strict as this 
  532. regular expression indicates. The property chunks VHDR, NAME, Copyright, 
  533. and AUTH may actually appear in any order as long as they all precede 
  534. the BODY chunk. The optional data chunks ANNO, ATAK, and RLSE don't 
  535. have to precede the BODY chunk. And of course, new kinds of chunks 
  536. may appear inside a FORM 8SVX in the future.
  537.  
  538. `0C
  539. Appendix B. 8SVX Example
  540.  
  541. Here's a box diagram for a simple example containing the three octave 
  542. BODY shown earlier in Figure 2.
  543.  
  544.           +-----------------------------------+   
  545.           |'FORM'        362                | 
  546.           +-----------------------------------+   
  547.           |'8SVX'                      |     
  548.           +-----------------------------------+   
  549.           |  +-----------------------------+  |   
  550.           |  |'VHDR'          20       |  | 
  551.           |  |24,16,8,10000,3,0,1.0      |  |   
  552.           |  +-----------------------------+  |   
  553.           |  +-----------------------------+  |   
  554.           |  |'NAME'          11       |  |
  555.           |  |'bass guitar'         |  |   
  556.           |  +-----------------------------+  |   
  557.      |  0                    |
  558.           |  +-----------------------------+  |   
  559.           |  |'(c)'      20       |  |
  560.           |  |1985 Electronic Arts  |  |   
  561.           |  +-----------------------------+  |   
  562.           |  +-----------------------------+  |   
  563.           |  |'BODY'          280      |  |
  564.           |  |1, 2, 3, 4, ...       |  |   
  565.           |  +-----------------------------+  |   
  566.           +-----------------------------------+   
  567.  
  568. The "0" after the NAME chunk is a pad byte.
  569.  
  570. `0C
  571. Appendix B. Standards Committee
  572.  
  573. The following people contributed to the design of this IFF standard:
  574.  
  575. Bob "Kodiak" Burns, Commodore-Amiga
  576. R. J. Mical, Commodore-Amiga
  577. Jerry Morrison, Electronic Arts
  578. Greg Riker, Electronic Arts
  579. Steve Shaw, Electronic Arts
  580. Barry Walsh, Commodore-Amiga
  581.  
  582. The "0" after the NAME chunk is a pad byte.
  583.  
  584. `0C
  585. Appendix C. Fibonacci Delta Compression
  586.  
  587. This is Steve Hayes' Fibonacci Delta sound compression technique. 
  588. It's like the traditional delta encoding but encodes each delta in 
  589. a mere 4 bits. The compressed data is half the size of the original 
  590. data plus a 2-byte overhead for the initial value. This much compression 
  591. introduces some distortion, so try it out and use it with discretion.
  592.  
  593. To achieve a reasonable slew rate, this algorithm looks up each stored 
  594. 4-bit value in a table of Fibonacci numbers. So very small deltas 
  595. are encoded precisely while larger deltas are approximated. When it 
  596. has to make approximations, the compressor should adjust all the values 
  597. (forwards and backwards in time) for minimum overall distortion.
  598.  
  599. Here is the decompressor written in the C programming language.
  600.  
  601. /* Fibonacci delta encoding for sound data. */
  602.  
  603. BYTE codeToDelta[16] = {-34,-21,-13,-8,-5,-3,-2,-1,0,1,2,3,5,8,13,21};
  604.  
  605. /* Unpack Fibonacci-delta encoded data from n byte source buffer into 2*n byte
  606.  * dest buffer, given initial data value x. It returns the last data value x
  607.  * so you can call it several times to incrementally decompress the data. */
  608.  
  609. short D1Unpack(source, n, dest, x)
  610.      BYTE source[], dest[];
  611.      LONG n;
  612.      BYTE x;
  613.      {
  614.      BYTE d;
  615.      LONG i, lim;
  616.  
  617.      lim = n <<<< 1;
  618.      for (i = 0; i << lim; ++i)
  619.           {    
  620.           /* Decode a data nybble; high nybble then low nybble. */
  621.           d = source[i >> 1]; /* get a pair of nybbles */
  622.           if (i & 1)          /* select low or high nybble? */
  623.                d &= 0xf; /* mask to get the low nybble */
  624.           else
  625.                d >>= 4;  /* shift to get the high nybble */
  626.           x += codeToDelta[d];     /* add in the decoded delta */
  627.           dest[i] = x;        /* store a 1-byte sample */
  628.           }
  629.      return(x);
  630.      }
  631.  
  632. /* Unpack Fibonacci-delta encoded data from n byte source buffer into 2*(n-2)
  633.  * byte dest buffer. Source buffer has a pad byte, an 8-bit initial value,
  634.  * followed by n-2 bytes comprising 2*(n-2) 4-bit encoded samples. */
  635.  
  636. void DUnpack(source, n, dest)
  637.      BYTE source[], dest[];
  638.      LONG n;
  639.      {
  640.           D1Unpack(source + 2, n - 2, dest, source[1]);
  641.      }
  642.  
  643.